//
// Created by win10 on 2021/1/4.
//
#ifndef BACKHEADSHARE_EVENTEMITTERSYNC_H
#define BACKHEADSHARE_EVENTEMITTERSYNC_H
#include "EventEmitter.h"


// implementation 1
class EventEmitterSync : public EventEmitter {
private:
    std::unordered_map <std::string, std::function<void()>> _handlers;
public:
    EventEmitterSync() = default;

    ~EventEmitterSync() override = default;

    void emit(const std::string &event) final {
        auto handler = _handlers[event];
        handler();
    }

    void on(const std::string &event, const std::function<void()> &handler) final {
        _handlers[event] = handler;
    }
};


#endif //BACKHEADSHARE_EVENTEMITTERSYNC_H
